package com.health.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.health.common.PageBean;
import com.health.common.QueryPageBean;
import com.health.domain.CheckGroup;
import com.health.domain.User;
import com.health.mapper.UserMapper;
import com.health.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String username, String password) {

        return userMapper.login(username, password);
    }

    @Override
    public User findByUsername() {
        return userMapper.findByUsername();
    }

    @Override
    public PageBean<CheckGroup> findByPage(QueryPageBean queryPageBean) {
        Integer page = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        PageHelper.startPage(page,pageSize);

        List<CheckGroup> groupList = userMapper.findList(queryPageBean);
        Page<CheckGroup> p = (Page<CheckGroup>) groupList;

        return new PageBean<>(p.getTotal(),p.getResult());
    }

}
